package eu.jba.denshijisho.dao;

import eu.jba.denshijisho.R;
import eu.jba.denshijisho.entity.Configuration;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;

public class ConfigurationDao extends AbstractDao<Configuration> {

	public static final String KEY_ROWID = "_id";
	public static final String KEY_VARIABLE_NAME = "variableName";
	public static final String KEY_INTEGER_VALUE = "integerValue";
	public static final String KEY_STRING_VALUE = "stringValue";

	public ConfigurationDao(Context ctx) {
		super(ctx);
	}

	@Override
	protected String getTableName() {
		return getContext().getResources().getString(
				R.database.CONFIGURATION_TABLE);
	}

	@Override
	protected ContentValues getInitialValues(Configuration configuration) {
		final ContentValues initialValues = new ContentValues();
		initialValues.put(KEY_VARIABLE_NAME, configuration.getVariableName());
		initialValues.put(KEY_INTEGER_VALUE, configuration.getIntegerValue());
		initialValues.put(KEY_STRING_VALUE, configuration.getStringValue());
		return initialValues;
	}
	
	@Override
	protected String getRowIdColumnName(){
		return KEY_ROWID;
	}
	
	@Override
	protected String[] getColumns(){
		return new String[] {KEY_ROWID, KEY_VARIABLE_NAME, KEY_INTEGER_VALUE, KEY_STRING_VALUE};
	}
	
	@Override
	protected Configuration convertTo(Cursor cursor){
		final Configuration configuration = new Configuration(
			cursor.getInt(0), cursor.getString(1), cursor.getInt(2), cursor.getString(3)
		);
		return configuration;
	}
	
	@Override
	protected int getCreateResource(){
		return R.raw.create_table_configuration;
	}
	
	@Override
	protected int getUpdateResource(){
		return R.raw.update_table_configuration;
	}
	
	
}
